from mcp.server.fastmcp import FastMCP
from typing import Union

mcp = FastMCP("Math Calculator Server")

@mcp.tool()
def add(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
    """执行加法运算"""
    return a + b

@mcp.tool()
def subtract(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
    """执行减法运算"""
    return a - b

@mcp.tool()
def multiply(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
    """执行乘法运算"""
    return a * b

@mcp.tool()
def divide(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
    """执行除法运算，当除数为零时抛出异常"""
    if b == 0:
        raise ValueError("除数不能为零")
    return a / b

if __name__ == "__main__":
    mcp.run(transport="stdio")